const getComment = (animation_id) => {
    const formdata = new FormData();
    formdata.append('animation_id', animation_id);

    return dispatch => {
        let url = 'http://www.h5weixin.club:8000/ani_comment';
        fetch(url, {
            method: 'POST',
            mode: 'cors',
            body: formdata
        }).then(res => {
            return res.json()
        }).then(res => {
            if (res.code === 200) {
                dispatch({
                    type: 'GET_COMMENT_DATA',
                    data: res.data
                })
            }
        }).catch(err => {
            console.log(err);
        })
    }
}

const addComment = (user_id, animation_id, comment_content, time) => {
    const formdata = new FormData();
    formdata.append('user_id', user_id);
    formdata.append(' animation_id', animation_id);
    formdata.append('comment_content', comment_content);
    formdata.append('time', time);

    return dispatch => {
        let url = 'http://www.h5weixin.club:8000/comment_info';
        fetch(url, {
            method: 'POST',
            mode: 'cors',
            body: formdata
        }).then(res => {
            console.log(res);
            // return res.json()
        }).catch(err => {
            console.log(err);
        })
    }
}

export { getComment, addComment };